package edu.sctu.lab03;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by 1 on 2018/6/3.
 */
public class RegisterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        String username = req.getParameter("username"); //获取jsp页面传过来的参数
        String password = req.getParameter("password");

        User user = new User(); //实例化一个对象，组装属性
        user.setUsername(username);
        user.setPassword(password);
            req.setAttribute("username", username);  //向request域中放置参数
            //request.setAttribute("john", "注册成功");
            req.getRequestDispatcher("/login.jsp").forward(req, resp);  //转发到登录页面
            resp.sendRedirect("default.jsp");//重定向到首页
        }
    }
